package com.zj.sms.constant;

public class CommonUtil {
	public static void main(String[] args) {
		String a = "http:\\/a.com/bdg/c.html/h/g";
		System.out.println(a);
		int b = getIndexTag(a,Constants.tag,Constants.fixNum);
		System.out.println(a.substring(0,b));
	}
	/**
	 * 返回字符串url内第index个tag的位置，如果没有足够tag则返回-1
	 * @param url
	 * @param tag
	 * @param index
	 * @return http://a.com/bdg/c.html/h/g -> http://a.com/bdg
	 */
	public static String getPreUrl(String url , String tag, int index){
		int n = getIndexTag(url,tag,index);
		if(n == -1) return null;
		return url.substring(0,n);
	}
	/**
	 * 返回字符串url内第index个tag的位置，如果没有足够tag则返回-1
	 * @param url 给定字符串
	 * @param tag 标志字符/\\ 即如果url中包含\或者包含/
	 * @param index 找到第index个tag
	 * @return http://a.com/bdg/c.html/h/g -> http://a.com/bdg
	 */
	public static int getIndexTag(String url,String tag,int index){
		int n = 0;
		for(int i=0;i<url.length();i++){
			if(tag.contains(String.valueOf(url.charAt(i)))){
				if(++n == index){
					return i;
				}
			}
		}
		return -1;
	}
}
